var myChart = echarts.init(document.getElementById('main-map'));    
    option = {
	tooltip : {
		trigger: 'item'
	},
    series : [
        {
		tooltip: {
				trigger: 'item',
				formatter:function (params) {
					  var res = params.name+'<br/>';
					  if (typeof(params.data.count) == "undefined") { 
						   params.data.count='-';
					  }
					  res+=''+params.value+'家<br/>';
					  // res+='占比: '+params.data.count;					  					  
					  return res;
				}
			},
			name: '',
			type: 'map',
			mapType: 'china',
			mapLocation: {//显示主地图的位置及其大小
				x: 'left',
				y: 'top',
				width: '50%'
			},
			roam: false,//地图不允许拖动
			selectedMode : 'single',
			itemStyle:{
				normal:{label:{show:true},color:'#ffbfa7'},
				emphasis:{label:{show:true},color:'#ff7f50'}
			},
            data:[
				{name: '北京', selected:false, value: 2916},
				{name: '天津', selected:false, value: 1236},
				{name: '上海', selected:false, value: 836},
				{name: '重庆', selected:false, value: 226},
				{name: '河北', selected:false, value: 324},
				{name: '河南', selected:false, value: 6212},
				{name: '云南', selected:false, value: 9635},
				{name: '辽宁', selected:false, value: 2926},
				{name: '黑龙江', selected:false, value: 2916},
				{name: '湖南', selected:false, value: 9212},
				//{name: '安徽', selected:false, value: 20},
				//{name: '山东', selected:false, value: 456},
				{name: '新疆', selected:false, value: 12212},
				{name: '江苏', selected:false, value: 924},
				{name: '浙江', selected:false, value: 24212},
				{name: '江西', selected:false, value: 2327},
				{name: '湖北', selected:false, value: 2396},
				{name: '广西', selected:false, value: 2896},
				{name: '甘肃', selected:false, value: 28896},
				{name: '山西', selected:false, value: 28596},
				{name: '内蒙古',selected:false, value: 25596},
				{name: '陕西', selected:false, value: 29556},
				{name: '吉林', selected:false, value: 2986},
				{name: '福建', selected:false, value: 54212},
				{name: '贵州', selected:false, value: 24296},
				{name: '广东', selected:false, value: 21423},
				{name: '青海', selected:false, value: 29456},
				{name: '西藏', selected:false, value: 4575},
				{name: '四川', selected:false, value: 34545},
				{name: '宁夏', selected:false, value: 44525},
				{name: '海南', selected:false, value: 2456},
				{name: '台湾', selected:false, value: 4566},
				{name: '香港', selected:false, value: 5673},
				{name: '澳门', selected:false, value: 346}
			]
        }
    ],
    animation: false
};
 
myChart.setOption(option, true); //显示国家地图
 
//var ecConfig = require('echarts/config');
//myChart.on(ecConfig.EVENT.MAP_SELECTED, function (param){//由于是标签式单文件引入所以这个模块化单文件引入的事件要改变,不能使用require
myChart.on(echarts.config.EVENT.MAP_SELECTED, function (param){//单击省份事件
    var selected = param.selected;
    var selectedProvince;
    var name;
    for (var i = 0, l = option.series[0].data.length; i < l; i++) {
        name = option.series[0].data[i].name;
        option.series[0].data[i].selected = selected[name];
        if (selected[name]) {
            selectedProvince = name;
        }
    }
    getProvinceMap(selectedProvince);//传递一个省，显示这个省的地图(这是自定义方法)
});
 
//选择地级市的单击事件
myChart.on(echarts.config.EVENT.CLICK, function (param){
   var seriesName=param.seriesName;
   if(seriesName.trim()=="地级市扫码地域"||seriesName.trim()==""){//由于全国地图和省地图都要触发这个事件，所以要判断是省还是地级市
   //alert(param.name);//地级市的名字
   }
});


//页面加载完之后默认选择省份以及需要展开的省地图
$(document).ready(function(){	
	var selectedProvince="福建";//默认展开福建的地图
    for (var i = 0, l = option.series[0].data.length; i < l; i++) {
        if(option.series[0].data[i].name==selectedProvince){//循环判断默认被选中
        option.series[0].data[i].selected = true;//设置默认选中 
        break;
        }
    }
    getProvinceMap(selectedProvince);//传递一个省，显示这个省的地图
});
 
//传递一个省，显示这个省的地图
function getProvinceMap(selectedProvince){
    // alert(selectedProvince);//所选择省的名字
    if (typeof selectedProvince == 'undefined') {
        option.series.splice(1);
        option.legend = null;
        option.dataRange = null;
        myChart.setOption(option, true);//如果选择省份不存在则显示国家
        return;
    }	
	option.dataRange = {
		orient: 'horizontal',
        x: 'right',
        min: 0,
        max: 60000,
        color:['#ff7f50','#ffdccf'],
        text:['高','低'],// 文本，默认为数值文本
        splitNumber:0
	};
    myChart.setOption(option, true);//显示省地图
}